<html>
<head>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>

<form class="layui-form" action="" style="margin-top: 20px;margin-right: 30px;">

    <input type="hidden" name="id" value="{$data.ad_id}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" value="{$data.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">位置</label>
        <div class="layui-input-block">
            <input type="radio" name="location" value="1" title="首页" {if condition="$data.location == 1"}checked{/if}>
            <input type="radio" name="location" value="2" title="开锁页"  {if condition="$data.location == 2"}checked{/if}>
            <input type="radio" name="location" value="3" title="可接订单页"  {if condition="$data.location == 3"}checked{/if}>
            <input type="radio" name="location" value="4" title="商家列表"  {if condition="$data.location == 4"}checked{/if}>
            <input type="radio" name="location" value="5" title="首页小图"  {if condition="$data.location == 5"}checked{/if}>
            <input type="radio" name="location" value="6" title="订单评论"  {if condition="$data.location == 6"}checked{/if}>
            <input type="radio" name="location" value="7" title="评论成功"  {if condition="$data.location == 7"}checked{/if}>
            <input type="radio" name="location" value="8" title="抽奖列表"  {if condition="$data.location == 8"}checked{/if}>
            <input type="radio" name="location" value="9" title="抽奖详情"  {if condition="$data.location == 9"}checked{/if}>
            <input type="radio" name="location" value="10" title="抽奖参与人员列表"  {if condition="$data.location == 10"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">跳转路径</label>
        <div class="layui-input-block">
            <input type="text" name="path" id="path" autocomplete="off" class="layui-input" value="{$data.path}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">appid</label>
        <div class="layui-input-block">
            <input type="text" name="appid" id="appid" autocomplete="off" class="layui-input" value="{$data.appid}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block" >

            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
            <div id="img" style="margin-top: 20px;">
                {if condition="$data.image != ''"}
                <img src='{$data.image}' style='width: 120px;'>
                <input type='hidden' name='image' value='{$data.image}'/>
                {/if}

            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
        </div>
    </div>
</form>


<script src="/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        //监听提交
        form.on('submit(formDemo)', function(data){
            var data = data.field;

            $.post("/ops/ad/edit", data, function (res) {
                var res = JSON.parse(res);
                if(res.errno==0){
                    layer.msg('操作成功')
                }

                window.parent.location.reload();
            });
            return false;
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div id=\"test1\"><img src='"+data.data.url+"' style='width: 120px;'>"
                    str += "<input type='hidden' name='image' value='"+data.data.url+"'/></div>"

                    $('#img').html(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });

</script>


</body>
</html>

